//
//  DreamViewController.m
//  Light
//
//  Created by 骁唐 on 15/8/27.
//  Copyright (c) 2015年 骁唐. All rights reserved.
//

#import "DreamViewController.h"
#import "WXApi.h"
#import "UserConfig.h"

@interface DreamViewController ()<UIGestureRecognizerDelegate>
//蒙版
@property (weak, nonatomic) IBOutlet UIView *DreamView;
@property (weak, nonatomic) IBOutlet UILabel *descripeLabel;
@property (weak, nonatomic) IBOutlet UILabel *warnLabel;
//梦境控制弹框
@property (weak, nonatomic) IBOutlet UIView *dreamControl;
//获取验证码
@property (weak, nonatomic) IBOutlet UIButton *getTesting;
@property (weak, nonatomic) IBOutlet UIImageView *backGround;
//验证码输入框
@property (weak, nonatomic) IBOutlet UITextField *testTextFied;


@end

@implementation DreamViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    
    //梦境控制  文案详情 设置介绍文本字距
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:MESSAGE_MENGJING_DESC];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
    [paragraphStyle setLineSpacing:8];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0,[MESSAGE_MENGJING_DESC length])];
    [_descripeLabel setAttributedText:attributedString];
    [_descripeLabel sizeToFit];
    
    //梦境控制 文案提醒
    NSMutableAttributedString *attributedString1 = [[NSMutableAttributedString alloc]initWithString:MESSAGE_MENGJING_WARNING];
    NSMutableParagraphStyle *paragraphStyle1 = [[NSMutableParagraphStyle alloc]init];
    [paragraphStyle1 setLineSpacing:5];
    [attributedString1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0,[MESSAGE_MENGJING_WARNING length])];
    [_warnLabel setAttributedText:attributedString1];
    [_warnLabel sizeToFit];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return  YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return [gestureRecognizer isKindOfClass:UIScreenEdgePanGestureRecognizer.class];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (IBAction)offDreamClick {
    self.dreamControl.hidden = YES;
    self.DreamView.hidden = YES;
}
- (IBAction)backClick:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
//获取验证码
- (IBAction)getTestingClick {
//    NSString *weixinURL = @"weixin_schema://app_id?title=xxx&content=xxx";
//    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:weixinURL]];
//    
    if ([WXApi isWXAppInstalled]) {
        NSString *str = @"weixin://qr";
       [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    }else
    {
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"您没有安装微信，现在去安装" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alertView show];
    
    }
}
//确认跳转开关
- (IBAction)deterMine {
    if ([self.testTextFied.text isEqualToString:@"215929"]) {
        UserConfig *config = [UserConfig sharingUserConfig];
        [config setJudgeTestingSwitch:@"1"];
          [self performSegueWithIdentifier:@"dreamTODreamTwo" sender:nil];
    }
  
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //强制竖屏
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:
                                        UIInterfaceOrientationPortrait]  forKey:@"orientation"];
    long long int currentTimeInt = [TJJDefines getTimeIntSince1970Current];
    if (currentTimeInt>=16200&& currentTimeInt <=34200) {
        self.backGround.image = [UIImage imageNamed:@"backgroundOne"];
    }else if (currentTimeInt>34200 && currentTimeInt<=55800)
    {
        self.backGround.image = [UIImage imageNamed:@"backgroundTwo"];
    }else if (currentTimeInt>55800 && currentTimeInt<=70200)
    {
        self.backGround.image = [UIImage imageNamed:@"backgroundThree"];
    }else if(currentTimeInt >70200 || currentTimeInt<16200)
    {
        self.backGround.image = [UIImage imageNamed:@"background_night"];
    }
}

//验证码清除框
- (IBAction)clearTextClick {
    self.testTextFied.text = nil;
}

@end
